package com.xingdata.jjxc.utils;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.xingdata.jjxc.enty.NotificationEntity;

/**
 * 
*    
* 项目名称：JJXC_VPN   
* 类名称：WeatherTools   
* 类描述：   天气工具类
* 创建人：JiangMin 
* 创建时间：2015-6-2 上午11:54:00    
* 修改备注：   
* @version    
*
 */
public class WeatherTools {
	/**
	 * 根据天气获取对应转码
	 * @param weather_str
	 * @throws JSONException 
	 */
	public static HashMap<String, String> getWeatherCode(Context context) throws JSONException {
		String strJson = StringUtil.getAssetsFileToString(context,
				SystemInfo.JSONNAME);
		JSONObject jsonObject = new JSONObject(strJson);
		HashMap<String, String> weathMap = new HashMap<String, String>();
		try {
			JSONArray weatherJsonArray = jsonObject.optJSONArray("weathercode");
			for (int i = 0; i < weatherJsonArray.length(); i++) {
				weathMap.put(
						weatherJsonArray.getJSONObject(i).getString("weather"),
						weatherJsonArray.getJSONObject(i).getString("code"));
			}
			JSONArray messagetypeJsonArray = jsonObject.optJSONArray("messagetype");
			if (SystemInfo.messageCodeMap!=null) {
				SystemInfo.messageCodeMap.clear();
			}
			NotificationEntity notificationEntity=null;
			for (int i = 0; i < messagetypeJsonArray.length(); i++) {
				notificationEntity = new NotificationEntity();
//				notificationEntity.setMessageCode(messagetypeJsonArray.getJSONObject(i).optString("code"));
//				notificationEntity.setName(messagetypeJsonArray.getJSONObject(i).optString("name"));
				SystemInfo.messageCodeMap.put(messagetypeJsonArray.getJSONObject(i).optString("type"), notificationEntity);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return weathMap;
	}
	
	
	
	

}
;